<template>
    <div class="edit-popup">
        <popup ref="popupRef" :title="popupTitle" :async="true" width="700px">
            <el-tabs v-model="activeName">
                <el-tab-pane label="提交" name="first">
                    <el-form :inline="true" ref="formRef" class="mb-[-16px]">
                        <el-form-item prop="name" label="当前节点">
                            <el-input v-model="flowtype" class="w-[485px]" />
                        </el-form-item>
                        <el-form-item prop="name" label="下一节点">
                            <el-select v-model="isFallbackNode" clearable class="w-[485px]">
                                <el-option label="结束" value="1" />
                                <el-option label="初始" value="2" />
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="name" label="备注">
                            <el-input v-model="deptData" class="w-[485px]" :autosize="{ minRows: 2, maxRows: 4 }"
                                type="textarea" placeholder="同意" />
                        </el-form-item>
                        <el-form-item>
                            <div>
                                注：审核人员括号的数字表示待处理任务数量
                            </div>
                        </el-form-item>
                    </el-form>
                </el-tab-pane>
                <el-tab-pane label="流程信息" name="second">
                    <el-form :inline="true" ref="formRef" class="mb-[-16px]">
                        <el-form-item prop="name" label="流程类型">
                            <el-input v-model="flowtype" class="w-[485px]" />
                        </el-form-item>
                        <el-form-item prop="name" label="部门信息">
                            <el-input v-model="deptData" class="w-[485px]" />
                        </el-form-item>
                        <el-form-item prop="name" label="提交至退回节点">
                            <el-input v-model="deptData" class="w-[485px]" />
                        </el-form-item>
                        <el-form-item prop="name" label="更新时间">
                            <el-input v-model="deptData" class="w-[485px]" />
                        </el-form-item>
                    </el-form>
                    <el-table class="mt-4" size="large" :data="tableData">
                        <el-table-column label="序号" type="index" width="60" align="center" />
                        <el-table-column label="节点名称" prop="nodeName" min-width="80" align="center" />
                        <el-table-column label="人员类型" prop="staffType" min-width="80" align="center" />
                        <el-table-column label="审核人员" prop="auditor" min-width="80" align="center" />
                        <el-table-column label="下一步流程" prop="nextStep" min-width="80" align="center">
                        </el-table-column>
                    </el-table>
                </el-tab-pane>
            </el-tabs>
        </popup>
    </div>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'element-plus'

import Popup from '@/components/popup/index.vue'
import { detailByDeptId } from '@/api/deptFlow'

const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
const deptData = ref('基础信息')
const popupTitle = computed(() => {
    return mode.value == 'edit' ? '流程编辑' : '流程信息'
})
const formData = reactive({
    id: '',
    pid: '' as string | number,
    name: '',
    duty: '',
    mobile: '',
    sort: 0,
    isStop: 0
})
const activeName = 'first'
const activeNames = 'patent'
const rowData = ref({})
const flowtype = ref('')
const showfooter = false

// const handleSubmit = async () => {
//     await formRef.value?.validate()
//     mode.value == 'edit' ? await deptEdit(formData) : await deptAdd(formData)
//     popupRef.value?.close()
//     feedback.msgSuccess('操作成功')
//     emit('success')
// }

const open = async (type = 'add') => {
    mode.value = type
    popupRef.value?.open()

}

const setFormData = (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }
}
const getDetail = async (row: Record<string, any>, type: any) => {
    rowData.value = row
    flowtype.value = type
    deptData.value = row.name

}
const getdetailByDept = async () => {
    const listData = await detailByDeptId({
        type: '专利',
        proposalType: '提案流程'
    })
    console.log(listData, 'ppppppp')
}
getdetailByDept()

const handleClose = () => {
    emit('close')
}
const tableData = ref([
    { nodeName: '启动流程', staffType: '用户', allowEdit: true, auditor: '审计员1', nextStep: '2' },
    { nodeName: '节点2', staffType: '角色', allowEdit: true, auditor: '审计员2', nextStep: '3' },
    { nodeName: '结束', staffType: '岗位', allowEdit: true, auditor: '审计员3', nextStep: '0' }
]);

defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
